package com.ymatou.userservice.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.userservice.parameter.UserRequestDtoBean;
import com.ymatou.userservice.service.UserRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.model.YmtUsers;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;
/**
*查询用户推荐接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UserRequestDto{
	private static UserRequestDtoBean userrequestdtoBean;
	private static UserRequestDtoCall userrequestdtoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询用户推荐接口");
	}

	@Before
	public void caseUp() {
		userrequestdtoBean=new UserRequestDtoBean();
		userrequestdtoCall=new UserRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(userrequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserRequestDto_001() {
		Logger.start(true,"成功查询出用户信息");
		try {
			userrequestdtoBean.setIUserId(104);
			userrequestdtoBean.setLoginKeyWord("小土豆");
			userrequestdtoBean.setIncludeIdCard(true);
			userrequestdtoBean.setIncludeLevel(true);
			userrequestdtoBean.setIncludeLogoUrl(true);
			userrequestdtoCall.setData(userrequestdtoBean);
			userrequestdtoCall.callService();			
			
			YmtUsersWapper usersWapper = new YmtUsersWapper();
			YmtUsers user = usersWapper.getYmtUsers(104);
			Logger.verifyEquals("true", userrequestdtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.SUCCESS, userrequestdtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals(user.getIuserid(), ((Double)userrequestdtoCall.getResult().get("iUserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(user.getSloginid(), userrequestdtoCall.getResult().get("sLoginId"), "验证登陆Id");
			Logger.verifyEquals(user.getSphone(), userrequestdtoCall.getResult().get("sPhone"), "验证手机");
			Logger.verifyEquals(user.getSloginemail(), userrequestdtoCall.getResult().get("sLoginEmail"), "验证Email");
			Logger.verifyNotNull(userrequestdtoCall.getJsonObject().get("Result").getAsJsonObject().get("sPassword"), "sPassword非空");
			Logger.verifyNotNull(userrequestdtoCall.getJsonObject().get("Result").getAsJsonObject().get("sTradingPassword"), "sTradingPassword非空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UserRequestDto_002() {
		Logger.start(true,"不输入用户ID，成功查询出用户信息");
		try {
			userrequestdtoBean.setLoginKeyWord("土豆");
			userrequestdtoBean.setIncludeIdCard(true);
			userrequestdtoBean.setIncludeLevel(true);
			userrequestdtoBean.setIncludeLogoUrl(true);
			userrequestdtoCall.setData(userrequestdtoBean);
			userrequestdtoCall.callService();				
			
			YmtUsersWapper usersWapper = new YmtUsersWapper();
			YmtUsers user = usersWapper.getYmtUsers("土豆");
			Logger.verifyEquals("true", userrequestdtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.SUCCESS, userrequestdtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals(user.getIuserid(), ((Double)userrequestdtoCall.getResult().get("iUserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(user.getSloginid(), userrequestdtoCall.getResult().get("sLoginId"), "验证登陆Id");
			Logger.verifyEquals(user.getSphone(), userrequestdtoCall.getResult().get("sPhone"), "验证手机");
			Logger.verifyEquals(user.getSloginemail(), userrequestdtoCall.getResult().get("sLoginEmail"), "验证Email");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UserRequestDto_003() {
		Logger.start(false,"不输入用户ID和登陆ID，失败");
		try {
			userrequestdtoBean.setIncludeIdCard(true);
			userrequestdtoBean.setIncludeLevel(true);
			userrequestdtoBean.setIncludeLogoUrl(true);
			userrequestdtoCall.setData(userrequestdtoBean);
			userrequestdtoCall.callService();	
			
//			Logger.verifyEquals("错误的查询条件", userrequestdtoCall.getString("LastErrorMessage"), "验证Msg信息");
			Logger.verifyEquals("100", userrequestdtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", userrequestdtoCall.getString("Success"), "验证是否成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserRequestDto_004() {
		Logger.start(true,"只用userid成功查询出用户信息");
		try {
			String ip=TestDataManager.getRandomIp();
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			Integer userId = Integer.valueOf(UserMap.get("userId").toString());
			String UserName = (String) UserMap.get("loginId");
			userrequestdtoBean.setIUserId(userId);
			userrequestdtoCall.setData(userrequestdtoBean);
			userrequestdtoCall.callService();			
			
			YmtUsersWapper usersWapper = new YmtUsersWapper();
			YmtUsers user = usersWapper.getYmtUsers(userId);
			Logger.verifyEquals("true", userrequestdtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.SUCCESS, userrequestdtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals(user.getIuserid(), ((Double)userrequestdtoCall.getResult().get("iUserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(user.getSloginid(), userrequestdtoCall.getResult().get("sLoginId"), "验证登陆Id");
			Logger.verifyEquals(user.getSphone(), userrequestdtoCall.getResult().get("sPhone"), "验证手机");
			Logger.verifyEquals(user.getSloginemail(), userrequestdtoCall.getResult().get("sLoginEmail"), "验证Email");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserRequestDto_005() {
		Logger.start(true,"邮箱注册用户成功查询出用户信息");
		try {
			String ip=TestDataManager.getRandomIp();
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			Map UserMap =UserCallService.registerUser(email, TestDataManager.getPhoneNum(), ip);
			String AccessToken = (String) UserMap.get("token");
			Integer userId = Integer.valueOf(UserMap.get("userId").toString());
			String UserName = (String) UserMap.get("loginId");
			userrequestdtoBean.setIUserId(userId);
			userrequestdtoCall.setData(userrequestdtoBean);
			userrequestdtoCall.callService();			
			
			YmtUsersWapper usersWapper = new YmtUsersWapper();
			YmtUsers user = usersWapper.getYmtUsers(userId);
			Logger.verifyEquals("true", userrequestdtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.SUCCESS, userrequestdtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals(user.getIuserid(), ((Double)userrequestdtoCall.getResult().get("iUserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(user.getSloginid(), userrequestdtoCall.getResult().get("sLoginId"), "验证登陆Id");
			Logger.verifyEquals(user.getSphone(), userrequestdtoCall.getResult().get("sPhone"), "验证手机");
			Logger.verifyEquals(user.getSloginemail(), userrequestdtoCall.getResult().get("sLoginEmail"), "验证Email");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserRequestDto_006() {
		Logger.start(true,"用邮件成功查询出用户信息");
		try {
			String ip=TestDataManager.getRandomIp();
			String email=TestDataManager.getEmail();
			Map UserMap =UserCallService.registerUser(email, TestDataManager.getPhoneNum(), ip);
			String AccessToken = (String) UserMap.get("token");
			Integer userId = Integer.valueOf(UserMap.get("userId").toString());
			String UserName = (String) UserMap.get("loginId");
			userrequestdtoBean.setLoginKeyWord(email);
			userrequestdtoBean.setIncludeIdCard(true);
			userrequestdtoBean.setIncludeLevel(true);
			userrequestdtoBean.setIncludeLogoUrl(true);
			userrequestdtoCall.setData(userrequestdtoBean);
			userrequestdtoCall.callService();			
			
			YmtUsersWapper usersWapper = new YmtUsersWapper();
			YmtUsers user = usersWapper.getYmtUsers(104);
			Logger.verifyEquals("true", userrequestdtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.SUCCESS, userrequestdtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals(userId, ((Double)userrequestdtoCall.getResult().get("iUserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(UserName, userrequestdtoCall.getResult().get("sLoginId"), "验证登陆Id");
			Logger.verifyEquals(email, userrequestdtoCall.getResult().get("sLoginEmail"), "验证Email");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}